aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/scope-prompt/[scopes]/+server.ts
blob: f919b9c1e62a41a75a20c2868c5c83a49e6622a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { base } from '$app/paths';
import { checkScope } from '$lib/auth';
import { error, redirect } from '@sveltejs/kit';

export const GET = async (e) => {
  const scopes = e.params.scopes
    .split(' ')
    .flatMap((v) => v.split(','))
    .flatMap((v) => v.split('+'))
    .filter((v) => v);
  if (
    checkScope(
      await e.locals.auth(),
      scopes,
      true,
      base + '/scope-prompt/ok/if/' + scopes.join(',')
    )
  )
    throw redirect(303, base + '/scope-prompt/ok');
  else throw error(500, 'In server mode, this branch should be unreachable');
};